# -*- coding: utf-8 -*-  
import pandas as pd

web_stats = {
    'Day': [1, 2, 3, 4, 5, 6],
    'Visitors': [43, 34, 65, 56, 29, 76],
    'Bounce Rate': [65, 67, 78, 65, 45, 52]
}

df = pd.DataFrame(web_stats)
print(df)
print(df.head(2))
print(df.tail(2))
#改变列名
df.columns = ['Day2',  'Visitors2', 'Bounce Rate2']
#只是想改变一个列，而不必输入所有的列
#df.rename(columns={'House_Price':'Prices'}, inplace=True)
#设置索引
df.set_index('Day2', inplace=True)
print(df.head(2))

df.to_csv('newcsv.csv')
#不想要标题设置 header
df[['Visitors2','Bounce Rate2']].to_csv('newcsv2.csv', header=False)
#文件没有标题设置names   导入时设置索引
df2 = pd.read_csv('newcsv2.csv', names=['Day', 'Visitors', 'Bounce Rate'], index_col=0)
print(df2.head())
